package com.lahuan.demo.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lahuan.config.kafka.ConsumerImpl;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import com.lahuan.demo.service.OrderService;
import com.lahuan.demo.entity.Order;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 订单 控制器
 * </p>
 * @author lahuan
 * @since 2021-12-15
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value = "t_order", tags = "订单接口")
@RequestMapping("/demo/order")
public class OrderController {

    private final KafkaTemplate<String,String> kafkaTemplate;
    @Value("${spring.kafka.template.default-topic}")
    private String topic;
    private final ConsumerImpl consumer;
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Order order) {
        kafkaTemplate.send(new ProducerRecord<>(topic, 2, UUID.randomUUID().toString().substring(0,8), JSON.toJSONString(order)) );
        return Result.ok(null,"success");
    }

    @GetMapping("/list")
    public Result<List<Order>> list(long start, long len ) {
        //重放
        return Result.ok(consumer.consumeOrder(start,len),"success");
    }




}
